Program to Insert an image in to the table
import java.sql.*;
import java.io.*;
public class Sample
{
public static void main(String args[])throws IOException
{
Connection con=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:vision","scott","tiger");
String fna=”c:/jdk1.5/abc.gif”;
File f=new File(fna);
FileInputStream fin =new FileInputStream(f);
byte []image=new byte[(int)f.length()];
fin.read(image);
String s=”insert into abc values(?,?)”;
PreparedStatement ps=con.prepareStatement(s);
ps.setString(1,f.getName());
ps.setBytes(2,image);
ps.executeUpdate();
ps.close();
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
catch(SQLException e)
{
e.printStackTrace();
}
finally
{
try
{
if(con!=null)
con.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
}
}